<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
// [js] 写一个获取当前url查询字符串中的参数的方法
function params(search) {
  // const search = window.location.search;
  search = search.substr(1, search.length);
  const res = {};
  if (!search) return res;
  search.split('&').map(item => {
    const [key, value] = item.split('=');
    res[key] = decodeURIComponent(value);
  });
  return res;
}
// console.log(https://mbd.baidu.com/newspage/data/landingsuper?context=%7B%22nid%22%3A%22news_9665133882961143405%22%7D&n_type=0&p_from=1);
let url = `https://mbd.baidu.com/newspage/data/landingsuper?context=%7B%22nid%22%3A%22news_9665133882961143405%22%7D&n_type=0&p_from=1`
console.log(params(url));
params(url)
function urlParam(url){
    const param = {};
    url.replace(/([^&=?]+)=([^&]+)/g,(m,$1,$2)=> param[$1] = $2);
    return param;
}

console.log(urlParam(url));
  </script>
</body>
</html>